<template>
	<view class="charts-box">
		<u-gap height="20" bgColor="#F5F7FA"></u-gap>
		<view style="text-align: center; padding-top: 20px">注浆量情况</view>
		<qiun-data-charts type="area" :opts="opts" :chartData="chartData" ontouch canvas2d />

		<view class="table-con" :class="[isShow ? 'height-all' : 'height-init']">
			<view v-for="(item, index) in (tableList || [])" :key="index">
				<view class="top">
					<view class="title">深度/米</view>
					<view class="num" v-for="(item1, index1) in item.dateArray" :key="index1">{{ item1 }}</view>
				</view>
				<view class="top" v-for="(item1, index1) in item.dataArray" :key="index1"
					:class="index1 % 2 === 0 ? 'white' : 'weight'">
					<view class="title">{{ item1.label }}</view>
					<view class="num" v-for="(item2, index2) in item1.dataList" :key="index2">{{ item2 }}</view>
				</view>
			</view>
		</view>
		<view @click="isShow = !isShow" class="text-operation">
			<view style="margin: auto; display: flex; align-items: center">
				<view class="img-down"></view>
				<view>{{ isShow ? '收起' : '展开查看全部' }}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import QiunDataCharts from '../../components/qiun-data-charts/components/qiun-data-charts/qiun-data-charts.vue';
	export default {
		components: {
			QiunDataCharts
		},
		data() {
			return {
				tableList: [],
				chartData: {},
				isShow: false,
				//您可以通过修改 config-ucharts.js 文件中下标为 ['area'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts: {
					color: ['#1890FF', '#CD0000'],
					padding: [10, 45, 0, 15],
					enableScroll: true,
					dataLabel: false,
					dataPointShape: false,
					legend: {
						show: true,
						position: 'top',
						float: 'right',
						itemGap: 20
					},
					xAxis: {
						boundaryGap: 'justify',
						disableGrid: true, // 禁用网格线
						scrollShow: true, // 开启横向滚动
						scrollAlign: 'left', // 滚动后左对齐
						itemCount: 4,
						boundaryGap: 'justify',
						title: '深度',
						titleOffsetX: 15,
					},
					yAxis: {
						gridType: 'dash',
						dashLength: 8,
						showTitle: true,
						data: [{
							title: '注浆量/升',
							titleFontSize: 14,
							titleOffsetY: -15,
							titleOffsetX: 10
						}]
					},
					extra: {
						area: {
							type: 'curve',
							opacity: 0.9,
							addLine: true,
							width: 3,
							gradient: true,
							activeType: 'none'
						}
					}
				}
			};
		},
		methods: {
			init(data) {
				this.tableList = data.tableList || []
				this.getServerData(data)
			},
			getServerData(data) {
				const {
					dateArray,
					dataArray
				} = data
				this.chartData = {
					categories: dateArray || [],
					series: dataArray.map(item => ({
						name: item.label + '注浆量',
						color: item.color,
						data: item.dataList.map(item1 => item1.data),
						legendShape: 'rect'
					}))
				};
			}
		}
	};
</script>

<style lang="scss" scoped>
	.table-con {
		padding: 20px;
		overflow-y: hidden;

		.top {
			display: flex;
			align-items: center;
			padding: 12px 10px;
			text-align: center;
			color: #000000;
			font-size: 16px;
			font-weight: bold;
			background: #f5f7fa;

			.title {
				width: 65px;

			}

			.num {
				width: 58px;
			}

			&.weight {
				font-weight: 500;
				color: #445469;
			}

			&.white {
				background-color: #ffffff;
				color: #445469;
				font-weight: 500;
			}
		}
	}

	.text-operation {
		display: flex;
		align-items: center;
		color: #2f80ed;
		font-weight: 500;
		font-size: 16px;
		padding: 20px 0;

		.img-down {
			height: 20px;
			width: 20px;
			background: url('@/subpackage-overhaul/static/down.png') no-repeat 100% 100%;
			margin-right: 5px;
		}
	}

	.height-all {
		max-height: initial; //这是啥意思  回到初始化的状态
	}

	.height-init {
		max-height: 150px;
	}
</style>